package com.gaojiawei.multiThread18_CompletableFutureTask;

import java.util.concurrent.CompletableFuture;

/**
 * thenAccept 前置任务先执行，后置任务会接收前置任务的返回结果，但是后置任务不返回结果
 */
public class L04_ThenAccept {

    public static void main(String[] args) {
        testThenAccept();
    }

    public static void testThenAccept(){
        CompletableFuture<String> taskA = CompletableFuture.supplyAsync(()->{
            System.out.println("begin a");
            System.out.println("finish a");
            return "finish a";

        });

        taskA.thenAccept((res)->{
            System.out.println("begin b");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(res);
            System.out.println("finish b");
        });
    }

    //thenAcceptAsync 异步但是同理。



}
